package com.yami.shop.platform.controller;

import com.yami.shop.bean.dto.SpuSeriesDTO;
import com.yami.shop.bean.model.SpuSeries;
import com.yami.shop.bean.vo.SpuSeriesVO;
import com.yami.shop.common.bean.PageDTO;
import com.yami.shop.common.bean.PageVO;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.service.SpuSeriesRelationService;
import com.yami.shop.service.SpuSeriesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 商品系列
 */
@RestController
@RequestMapping("/platform/spuSeries")
@Tag(name = "商品系列")
public class SpuSeriesController {

    @Autowired
    private SpuSeriesService spuSeriesService;

    @Autowired
    private SpuSeriesRelationService spuSeriesRelationService;

    @GetMapping("/ua/getList")
    @Operation(summary =  "获取系列列表", description = "获取系列列表")
    public ServerResponseEntity<PageVO<SpuSeries>> getList(@Valid PageDTO pageDTO, String seriesName) {
        PageVO<SpuSeries> spuSeriesList = spuSeriesService.getSpuSeriesList(pageDTO,seriesName);
        return ServerResponseEntity.success(spuSeriesList);
    }

    @GetMapping("/dele")
    @Operation(summary =  "系列删除", description = "系列删除")
    public ServerResponseEntity<Void> deleteSpuSeries(@Valid int id) {
        spuSeriesService.deleteSpuSeries(id);
        return ServerResponseEntity.success();
    }

    @PostMapping("/insertSpuSeries")
    @Operation(summary =  "系列添加", description = "系列添加")
    public ServerResponseEntity<Void> insertSpuSeries(@RequestBody SpuSeriesDTO spuSeriesDTO) {
        spuSeriesService.insertSpuSeries(spuSeriesDTO);
        return ServerResponseEntity.success();
    }

    @PostMapping("/updateSpuSeries")
    @Operation(summary =  "系列修改", description = "系列修改")
    public ServerResponseEntity<Void> updateSpuSeries(@RequestBody SpuSeriesDTO spuSeriesDTO) {
        spuSeriesService.updateSpuSeries(spuSeriesDTO);
        return ServerResponseEntity.success();
    }

    @GetMapping("/getInfo")
    @Operation(summary =  "根据id查询详情", description = "根据id查询详情")
    public ServerResponseEntity<SpuSeriesVO> getInfo(@Valid int id) {
        SpuSeriesVO spuSeriesVOInfo = spuSeriesService.getSpuSeriesVOInfo(id);
        return ServerResponseEntity.success(spuSeriesVOInfo);
    }

    @GetMapping("/deleByproductId")
    @Operation(summary =  "根据id查询详情", description = "根据id查询详情")
    public ServerResponseEntity<Void> deleByproductId(@Valid Integer product) {
        spuSeriesRelationService.deleByproductId(product);
        return ServerResponseEntity.success();
    }
}
